class CPFValidator < ActiveModel::Validator
  
  def validate(record)
    record.errors[:cpf] << "Formato de CPF invalido" unless formato_cpf(record.cpf)
  end
  
  def formato_cpf(cpf)
    regex = %r{^(\d{3}\.\d{3}\.\d{3}-\d{2})|(\d{11})$}xi
    cpf =~ regex
  end
  
end